﻿/********************************************************************
	created:	2011-8-17   16:07
	author:		Lifan Su
	
	purpose:	calculate all of the hashes implemented
*********************************************************************/

#include <_cstdint.hpp>

#include <crc32.h>
#include <crc64.h>
#include <md5.h>
#include <sha1.h>
#include <sha224.h>
#include <sha256.h>
#include <sha384.h>
#include <sha512.h>
#include <tiger192.h>
#include <cstdlib>

#include <cstdio>
#include <iostream>
#include <ctime>

using std::fopen;
using std::cout;
using std::wcout;
using std::endl;
using std::locale;
using std::cin;
using std::rand;
using std::fread;
using std::srand;
using std::time;

using std::uint8_t;


CRC32_c crc32c;
CRC32_d crc32d;
CRC64_c crc64c;
CRC64_d crc64d;
MD5_c md5c;
MD5_d md5d;
SHA1_c sha1c;
SHA1_d sha1d;
SHA224_c sha224c;
SHA224_d sha224d;
SHA256_c sha256c;
SHA256_d sha256d;
SHA384_c sha384c;
SHA384_d sha384d;
SHA512_c sha512c;
SHA512_d sha512d;
TIGER192_c tiger192c;
TIGER192_d tiger192d;

uint8_t crc32[4];
uint8_t crc64[8];
uint8_t md5[16];
uint8_t sha1[20];
uint8_t sha224[28];
uint8_t sha256[32];
uint8_t sha384[48];
uint8_t sha512[64];
uint8_t tiger192[24];

uint8_t fd[0x8000];
uint32_t used_buffer;
uint32_t calced_len = 0;

uint32_t read_length[] = {
    UINT32_C(0x00000ffe), UINT32_C(0x00004f71), UINT32_C(0x00006986), UINT32_C(0x0000202c), 
    UINT32_C(0x000002f6), UINT32_C(0x00004615), UINT32_C(0x00007b34), UINT32_C(0x00005d8f), 
    UINT32_C(0x000079c9), UINT32_C(0x000041ed), UINT32_C(0x00001efb), UINT32_C(0x00000394), 
    UINT32_C(0x00004dee), UINT32_C(0x00000424), UINT32_C(0x000068a2), UINT32_C(0x000010f5), 
    UINT32_C(0x00001506), UINT32_C(0x00005668), UINT32_C(0x00001b76), UINT32_C(0x00001ade), 
    UINT32_C(0x00003261), UINT32_C(0x00006656), UINT32_C(0x000067ec), UINT32_C(0x000023fc), 
    UINT32_C(0x000021c4), UINT32_C(0x00007532), UINT32_C(0x00002c87), UINT32_C(0x000069d8), 
    UINT32_C(0x00005f69), UINT32_C(0x00002fdc), UINT32_C(0x00003dfc), UINT32_C(0x00001c63), 
    UINT32_C(0x00001148), UINT32_C(0x000042ff), UINT32_C(0x00007a95), UINT32_C(0x000033d1), 
    UINT32_C(0x00005595), UINT32_C(0x00007f8c), UINT32_C(0x00002cd3), UINT32_C(0x000058ab), 
    UINT32_C(0x00005a8a), UINT32_C(0x00002367), UINT32_C(0x00000157), UINT32_C(0x00001220), 
    UINT32_C(0x00002366), UINT32_C(0x00001a60), UINT32_C(0x00001402), UINT32_C(0x00002e9d), 
    UINT32_C(0x00001eb6), UINT32_C(0x00004b64), UINT32_C(0x0000585c), UINT32_C(0x00001a9d), 
    UINT32_C(0x000071d3), UINT32_C(0x000045f4), UINT32_C(0x00006132), UINT32_C(0x000019c1), 
    UINT32_C(0x00001dac), UINT32_C(0x000063d7), UINT32_C(0x00004b84), UINT32_C(0x00001623), 
    UINT32_C(0x000060c5), UINT32_C(0x0000330c), UINT32_C(0x0000509e), UINT32_C(0x000079e8), 
    UINT32_C(0x00007a80), UINT32_C(0x00003c03), UINT32_C(0x00004384), UINT32_C(0x00004714), 
    UINT32_C(0x0000339c), UINT32_C(0x0000780d), UINT32_C(0x00007d93), UINT32_C(0x000061a2), 
    UINT32_C(0x00004ffb), UINT32_C(0x00000c10), UINT32_C(0x00007e66), UINT32_C(0x00003fd5), 
    UINT32_C(0x00004da8), UINT32_C(0x00001b7f), UINT32_C(0x000042f7), UINT32_C(0x000074c9), 
    UINT32_C(0x00001518), UINT32_C(0x00004789), UINT32_C(0x00001806), UINT32_C(0x0000494d), 
    UINT32_C(0x00007eb0), UINT32_C(0x00002e91), UINT32_C(0x00006bbf), UINT32_C(0x000056f5), 
    UINT32_C(0x00005188), UINT32_C(0x00007fdf), UINT32_C(0x00006297), UINT32_C(0x0000596a), 
    UINT32_C(0x00001f6f), UINT32_C(0x00007795), UINT32_C(0x00003377), UINT32_C(0x00002a05), 
    UINT32_C(0x0000222f), UINT32_C(0x000056e4), UINT32_C(0x00000f1c), UINT32_C(0x0000199c), 
    UINT32_C(0x00007e12), UINT32_C(0x00002c7f), UINT32_C(0x000016be), UINT32_C(0x00001c9c), 
    UINT32_C(0x00000da4), UINT32_C(0x00000150), UINT32_C(0x000025ef), UINT32_C(0x00007d58), 
    UINT32_C(0x00001abb), UINT32_C(0x00003d6b), UINT32_C(0x000073c7), UINT32_C(0x000008a1), 
    UINT32_C(0x000028b5), UINT32_C(0x00005940), UINT32_C(0x00004f3e), UINT32_C(0x00006897), 
    UINT32_C(0x00003401), UINT32_C(0x00002f14), UINT32_C(0x00007ad9), UINT32_C(0x000021be), 
    UINT32_C(0x00000ae1), UINT32_C(0x000000b2), UINT32_C(0x00006b89), UINT32_C(0x00006655), 
    UINT32_C(0x0000236d), UINT32_C(0x0000055d), UINT32_C(0x00006ed0), UINT32_C(0x000033e3), 
    UINT32_C(0x000012dc), UINT32_C(0x0000140a), UINT32_C(0x00007c25), UINT32_C(0x00006f12), 
    UINT32_C(0x000009ff), UINT32_C(0x00003dcc), UINT32_C(0x0000359a), UINT32_C(0x000071c0), 
    UINT32_C(0x00007b0e), UINT32_C(0x00006c90), UINT32_C(0x00005bbc), UINT32_C(0x00003f54), 
    UINT32_C(0x00004ca7), UINT32_C(0x00005a0a), UINT32_C(0x000038ba), UINT32_C(0x0000534e), 
    UINT32_C(0x00003e14), UINT32_C(0x000072ef), UINT32_C(0x000046ca), UINT32_C(0x00003e23), 
    UINT32_C(0x000060cd), UINT32_C(0x00007a65), UINT32_C(0x000015c9), UINT32_C(0x00000447), 
    UINT32_C(0x00004b3d), UINT32_C(0x000001b8), UINT32_C(0x00003421), UINT32_C(0x0000738b), 
    UINT32_C(0x000068c9), UINT32_C(0x0000084e), UINT32_C(0x00001ef0), UINT32_C(0x000062a9), 
    UINT32_C(0x00000b0f), UINT32_C(0x000057dd), UINT32_C(0x00007d67), UINT32_C(0x00000f1d), 
    UINT32_C(0x0000206b), UINT32_C(0x000070db), UINT32_C(0x00002b70), UINT32_C(0x00000d37), 
    UINT32_C(0x000033c0), UINT32_C(0x00001b36), UINT32_C(0x00005793), UINT32_C(0x00007e6f), 
    UINT32_C(0x00001975), UINT32_C(0x00006f46), UINT32_C(0x0000381a), UINT32_C(0x000001f8), 
    UINT32_C(0x00006dbd), UINT32_C(0x00006b00), UINT32_C(0x00001b73), UINT32_C(0x00001398),
    UINT32_C(0x0000481c), UINT32_C(0x0000676c), UINT32_C(0x000057d7), UINT32_C(0x00004cb6), 
    UINT32_C(0x00004827), UINT32_C(0x00000259), UINT32_C(0x00005e29), UINT32_C(0x00003bb5), 
    UINT32_C(0x00005f8b), UINT32_C(0x0000504f), UINT32_C(0x00007421), UINT32_C(0x00004580), 
    UINT32_C(0x00007d50), UINT32_C(0x00006ac5), UINT32_C(0x000059a9), UINT32_C(0x00004566), 
    UINT32_C(0x00007e5f), UINT32_C(0x00002e94), UINT32_C(0x00005d87), UINT32_C(0x00005f29), 
    UINT32_C(0x00000742), UINT32_C(0x00003eac), UINT32_C(0x0000253d), UINT32_C(0x00003751), 
    UINT32_C(0x00002b2c), UINT32_C(0x00001f05), UINT32_C(0x00002c2d), UINT32_C(0x000005c6), 
    UINT32_C(0x00000439), UINT32_C(0x00007bd9), UINT32_C(0x00003e01), UINT32_C(0x0000369e), 
    UINT32_C(0x000020f6), UINT32_C(0x00007111), UINT32_C(0x0000704a), UINT32_C(0x00000d34), 
    UINT32_C(0x00006b24), UINT32_C(0x000065fd), UINT32_C(0x00005f67), UINT32_C(0x00007d7a), 
    UINT32_C(0x00006bb9), UINT32_C(0x00005147), UINT32_C(0x000032a9), UINT32_C(0x00002f90), 
    UINT32_C(0x00001028), UINT32_C(0x0000792a), UINT32_C(0x00002bb5), UINT32_C(0x00006195), 
    UINT32_C(0x000054e2), UINT32_C(0x000003df), UINT32_C(0x00004529), UINT32_C(0x00001bbd), 
    UINT32_C(0x0000791d), UINT32_C(0x00006c58), UINT32_C(0x00002482), UINT32_C(0x00006aa3), 
    UINT32_C(0x00001fd4), UINT32_C(0x00002f31), UINT32_C(0x0000633d), UINT32_C(0x000013e1), 
    UINT32_C(0x0000020f), UINT32_C(0x000043e4), UINT32_C(0x0000733c), UINT32_C(0x000078df), 
    UINT32_C(0x00001664), UINT32_C(0x0000363c), UINT32_C(0x0000226c), UINT32_C(0x00001be8), 
    UINT32_C(0x000051be), UINT32_C(0x0000740c), UINT32_C(0x000001a5), UINT32_C(0x00007b83), 
    UINT32_C(0x0000655d), UINT32_C(0x00002320), UINT32_C(0x000032d1), UINT32_C(0x00003800), 
    UINT32_C(0x00001e1e), UINT32_C(0x00001374), UINT32_C(0x00006251), UINT32_C(0x00003751), 
    UINT32_C(0x000048fd), UINT32_C(0x000021a4), UINT32_C(0x00006f9c), UINT32_C(0x00003b1b), 
    UINT32_C(0x000040d8), UINT32_C(0x00001da4), UINT32_C(0x00000929), UINT32_C(0x00001d0d), 
    UINT32_C(0x00000976), UINT32_C(0x000009b1), UINT32_C(0x00003f90), UINT32_C(0x00002571), 
    UINT32_C(0x00001bc7), UINT32_C(0x00004587), UINT32_C(0x000053ec), UINT32_C(0x00003000), 
    UINT32_C(0x0000476d), UINT32_C(0x000079d5), UINT32_C(0x00004583), UINT32_C(0x000012fb), 
    UINT32_C(0x00004d7c), UINT32_C(0x000057ee), UINT32_C(0x000062a9), UINT32_C(0x00007c77), 
    UINT32_C(0x0000187e), UINT32_C(0x000001c1), UINT32_C(0x000060e1), UINT32_C(0x000039f9), 
    UINT32_C(0x000035bb), UINT32_C(0x00002e0b), UINT32_C(0x00004046), UINT32_C(0x00001e42), 
    UINT32_C(0x000073b7), UINT32_C(0x00005ccb), UINT32_C(0x00007e29), UINT32_C(0x0000796c), 
    UINT32_C(0x000049fb), UINT32_C(0x00002ff7), UINT32_C(0x00005afc), UINT32_C(0x00005736), 
    UINT32_C(0x00006e18), UINT32_C(0x00003c6d), UINT32_C(0x0000376e), UINT32_C(0x0000779d), 
    UINT32_C(0x000039ea), UINT32_C(0x0000672c), UINT32_C(0x00004cd8), UINT32_C(0x000035ac), 
    UINT32_C(0x0000471a), UINT32_C(0x000022c4), UINT32_C(0x000044d8), UINT32_C(0x00005094), 
    UINT32_C(0x000063e6), UINT32_C(0x0000210b), UINT32_C(0x0000743b), UINT32_C(0x00004aff), 
    UINT32_C(0x00004525), UINT32_C(0x00004d12), UINT32_C(0x00003d21), UINT32_C(0x000054a2), 
    UINT32_C(0x00001985), UINT32_C(0x00002157), UINT32_C(0x00005c5b), UINT32_C(0x00007211), 
    UINT32_C(0x00006218), UINT32_C(0x00002e3c), UINT32_C(0x00002618), UINT32_C(0x000056d8), 
    UINT32_C(0x0000340f), UINT32_C(0x000064b8), UINT32_C(0x000075c1), UINT32_C(0x000025c7), 
    UINT32_C(0x000047c5), UINT32_C(0x0000794d), UINT32_C(0x00005521), UINT32_C(0x00000b8d), 
    UINT32_C(0x000078ff), UINT32_C(0x0000733a), UINT32_C(0x00001ec9), UINT32_C(0x00006789), 
    UINT32_C(0x00001c72), UINT32_C(0x00003bf1), UINT32_C(0x00001fb3), UINT32_C(0x000076dc), 
    UINT32_C(0x00004e85), UINT32_C(0x000042cb), UINT32_C(0x00007c25), UINT32_C(0x000035c3), 
    UINT32_C(0x00001f59), UINT32_C(0x000008fb), UINT32_C(0x00005bd8), UINT32_C(0x00006b24), 
    UINT32_C(0x00004006), UINT32_C(0x000029c1), UINT32_C(0x0000215a), UINT32_C(0x00001266), 
    UINT32_C(0x00001528), UINT32_C(0x000032e0), UINT32_C(0x000030b1), UINT32_C(0x00001786), 
    UINT32_C(0x0000529b), UINT32_C(0x00006151), UINT32_C(0x00000941), UINT32_C(0x00001967), 
    UINT32_C(0x00000482), UINT32_C(0x00001639), UINT32_C(0x000036f0), UINT32_C(0x0000266a), 
    UINT32_C(0x0000298e), UINT32_C(0x00001819), UINT32_C(0x00005e87), UINT32_C(0x0000273f), 
    UINT32_C(0x0000427d), UINT32_C(0x00007444), UINT32_C(0x0000695b), UINT32_C(0x00006bfb), 
    UINT32_C(0x00007ae0), UINT32_C(0x00001497), UINT32_C(0x0000142e), UINT32_C(0x00000f6a), 
    UINT32_C(0x00004f22), UINT32_C(0x00005d64), UINT32_C(0x00006550), UINT32_C(0x000024a6), 
    UINT32_C(0x000053c6), UINT32_C(0x000067af), UINT32_C(0x00004e09), UINT32_C(0x000062e8), 
    UINT32_C(0x000001f0), UINT32_C(0x00002b9d), UINT32_C(0x00007b3c), UINT32_C(0x0000439f), 
    UINT32_C(0x00002d27), UINT32_C(0x00002f29), UINT32_C(0x00001944), UINT32_C(0x000046bf), 
    UINT32_C(0x00000659), UINT32_C(0x00000d19), UINT32_C(0x00000f22), UINT32_C(0x0000515c), 
    UINT32_C(0x0000501f), UINT32_C(0x00006830), UINT32_C(0x000074da), UINT32_C(0x00005a77), 
    UINT32_C(0x00002843), UINT32_C(0x00001ea6), UINT32_C(0x0000491a), UINT32_C(0x00005a18), 
    UINT32_C(0x00000a80), UINT32_C(0x000051d5), UINT32_C(0x00002a1d), UINT32_C(0x00002e9d), 
    UINT32_C(0x00007088), UINT32_C(0x00001635), UINT32_C(0x000015cf), UINT32_C(0x00006c51), 
    UINT32_C(0x0000334c), UINT32_C(0x00005f8a), UINT32_C(0x00007532), UINT32_C(0x00004b40), 
    UINT32_C(0x00001177), UINT32_C(0x00007d5c), UINT32_C(0x00007700), UINT32_C(0x0000274a), 
    UINT32_C(0x00007f3b), UINT32_C(0x00003ba8), UINT32_C(0x00007d92), UINT32_C(0x00004677), 
    UINT32_C(0x00002351), UINT32_C(0x00007bd5), UINT32_C(0x00002400), UINT32_C(0x0000598a), 
    UINT32_C(0x0000253b), UINT32_C(0x000059e9), UINT32_C(0x00001e8a), UINT32_C(0x00006ad9), 
    UINT32_C(0x000030cd), UINT32_C(0x000031fd), UINT32_C(0x00007a36), UINT32_C(0x00002f5b), 
    UINT32_C(0x000052eb), UINT32_C(0x000019ef), UINT32_C(0x00007fbb), UINT32_C(0x00006e03), 
    UINT32_C(0x00001394), UINT32_C(0x00002356), UINT32_C(0x00003d9e), UINT32_C(0x0000714c), 
    UINT32_C(0x00007120), UINT32_C(0x000079bb), UINT32_C(0x00007d9b), UINT32_C(0x00003716), 
    UINT32_C(0x000020c5), UINT32_C(0x00003106), UINT32_C(0x00002946), UINT32_C(0x000052b0), 
    UINT32_C(0x00003860), UINT32_C(0x00005836), UINT32_C(0x000061f2), UINT32_C(0x00003536), 
    UINT32_C(0x00002572), UINT32_C(0x00002455), UINT32_C(0x00004fd2), UINT32_C(0x0000501d), 
    UINT32_C(0x00001569), UINT32_C(0x000047ab), UINT32_C(0x00006c5e), UINT32_C(0x0000460c), 
    UINT32_C(0x00003322), UINT32_C(0x00004933), UINT32_C(0x00004bf8), UINT32_C(0x00001ded), 
    UINT32_C(0x00005dab), UINT32_C(0x0000704b), UINT32_C(0x00002ad0), UINT32_C(0x00002c45), 
    UINT32_C(0x00003c4d), UINT32_C(0x000018af), UINT32_C(0x00004105), UINT32_C(0x000026c0), 
    UINT32_C(0x000053ca), UINT32_C(0x000002a8), UINT32_C(0x0000220d), UINT32_C(0x00001611), 
    UINT32_C(0x000000e3), UINT32_C(0x00007381), UINT32_C(0x00002b56), UINT32_C(0x000019f8),
    UINT32_C(0x00007c1d), UINT32_C(0x00003a3b), UINT32_C(0x0000462d), UINT32_C(0x000033a4), 
    UINT32_C(0x00004ac5), UINT32_C(0x00006c82), UINT32_C(0x000000e0), UINT32_C(0x00000a3c), 
    UINT32_C(0x00004132), UINT32_C(0x00006fdf), UINT32_C(0x0000431f), UINT32_C(0x00005db9), 
    UINT32_C(0x00007a4a), UINT32_C(0x0000232e), UINT32_C(0x000021a8), UINT32_C(0x00001bf6), 
    UINT32_C(0x00006848), UINT32_C(0x00003c53), UINT32_C(0x00001524), UINT32_C(0x00004c0a), 
    UINT32_C(0x000062bc), UINT32_C(0x00002e29), UINT32_C(0x0000184b), UINT32_C(0x000043d5), 
    UINT32_C(0x000055d2), UINT32_C(0x00002abb), UINT32_C(0x0000714f), UINT32_C(0x00005bd9), 
    UINT32_C(0x000076d8), UINT32_C(0x000015b7), UINT32_C(0x00002a78), UINT32_C(0x0000154b), 
    UINT32_C(0x000021fb), UINT32_C(0x00007b1f), UINT32_C(0x00007e0b), UINT32_C(0x0000666a), 
    UINT32_C(0x00004551), UINT32_C(0x00005e42), UINT32_C(0x00003971), UINT32_C(0x00002110), 
    UINT32_C(0x00007d1d), UINT32_C(0x000074eb), UINT32_C(0x00005b95), UINT32_C(0x00002787), 
    UINT32_C(0x0000454e), UINT32_C(0x000022d8), UINT32_C(0x0000728e), UINT32_C(0x0000639d), 
    UINT32_C(0x00006448), UINT32_C(0x0000496d), UINT32_C(0x00007c7e), UINT32_C(0x000033fb), 
    UINT32_C(0x000072e7), UINT32_C(0x00003faa), UINT32_C(0x00004fba), UINT32_C(0x000043b2), 
    UINT32_C(0x000025c1), UINT32_C(0x0000065b), UINT32_C(0x00004e2b), UINT32_C(0x00000017), 
    UINT32_C(0x00003bac), UINT32_C(0x00000c8e), UINT32_C(0x000067f4), UINT32_C(0x000020d1), 
    UINT32_C(0x00003581), UINT32_C(0x0000184a), UINT32_C(0x00003154), UINT32_C(0x00007630), 
    UINT32_C(0x00003b1f), UINT32_C(0x0000277e), UINT32_C(0x00000fce), UINT32_C(0x000071c1), 
    UINT32_C(0x000051b2), UINT32_C(0x00005d38), UINT32_C(0x00004288), UINT32_C(0x00001d1f), 
    UINT32_C(0x00004735), UINT32_C(0x00004f17), UINT32_C(0x000049f2), UINT32_C(0x0000730b), 
    UINT32_C(0x00007735), UINT32_C(0x00004703), UINT32_C(0x000072a7), UINT32_C(0x00004ebf), 
    UINT32_C(0x00004cd8), UINT32_C(0x00004d1b), UINT32_C(0x00000798), UINT32_C(0x00006580), 
    UINT32_C(0x0000261f), UINT32_C(0x00000def), UINT32_C(0x00006f67), UINT32_C(0x00007e73), 
    UINT32_C(0x00007c68), UINT32_C(0x000070f0), UINT32_C(0x00003911), UINT32_C(0x00005cb1), 
    UINT32_C(0x00007637), UINT32_C(0x00007325), UINT32_C(0x00005bd0), UINT32_C(0x00000f9d), 
    UINT32_C(0x00004635), UINT32_C(0x00001a1f), UINT32_C(0x00002e40), UINT32_C(0x00001d76), 
    UINT32_C(0x00007b79), UINT32_C(0x0000132e), UINT32_C(0x000058c0), UINT32_C(0x00003c28), 
    UINT32_C(0x00002707), UINT32_C(0x000052d5), UINT32_C(0x0000471b), UINT32_C(0x00000c68), 
    UINT32_C(0x00007a96), UINT32_C(0x0000487c), UINT32_C(0x00005d68), UINT32_C(0x00000aff), 
    UINT32_C(0x00004497), UINT32_C(0x00007a65), UINT32_C(0x0000742e), UINT32_C(0x00002c66), 
    UINT32_C(0x00006d72), UINT32_C(0x00001de1), UINT32_C(0x00005fcc), UINT32_C(0x00005694), 
    UINT32_C(0x00005a13), UINT32_C(0x00007fc4), UINT32_C(0x00000718), UINT32_C(0x00002d14), 
    UINT32_C(0x000057a5), UINT32_C(0x00005116), UINT32_C(0x00004d47), UINT32_C(0x0000635a), 
    UINT32_C(0x0000749d), UINT32_C(0x00002c0b), UINT32_C(0x0000530d), UINT32_C(0x00000957), 
    UINT32_C(0x00006afb), UINT32_C(0x00006535), UINT32_C(0x00005304), UINT32_C(0x0000064b), 
    UINT32_C(0x00007fcc), UINT32_C(0x00007cf9), UINT32_C(0x00001d52), UINT32_C(0x000035db), 
    UINT32_C(0x00007bf4), UINT32_C(0x00004540), UINT32_C(0x00007687), UINT32_C(0x00005b63), 
    UINT32_C(0x0000222a), UINT32_C(0x00000f6e), UINT32_C(0x00005dc4), UINT32_C(0x00005f8d), 
    UINT32_C(0x00004644), UINT32_C(0x00007698), UINT32_C(0x00007e22), UINT32_C(0x00000c23), 
    UINT32_C(0x000069b5), UINT32_C(0x000019f2), UINT32_C(0x00004f51), UINT32_C(0x00003a21), 
    UINT32_C(0x00000154), UINT32_C(0x00005b86), UINT32_C(0x00002980), UINT32_C(0x0000260f), 
    UINT32_C(0x0000485f), UINT32_C(0x0000772c), UINT32_C(0x0000507d), UINT32_C(0x00005e8d), 
    UINT32_C(0x000044bf), UINT32_C(0x000005b6), UINT32_C(0x00003a1e), UINT32_C(0x00000130), 
    UINT32_C(0x0000608d), UINT32_C(0x0000406b), UINT32_C(0x000013df), UINT32_C(0x0000398c), 
    UINT32_C(0x00003cd6), UINT32_C(0x000018b7), UINT32_C(0x00004bcc), UINT32_C(0x00003692), 
    UINT32_C(0x0000219b), UINT32_C(0x00007820), UINT32_C(0x000020a2), UINT32_C(0x00000a1d), 
    UINT32_C(0x00002f1c), UINT32_C(0x00003c7c), UINT32_C(0x00007d31), UINT32_C(0x000026c7), 
    UINT32_C(0x00003457), UINT32_C(0x00004461), UINT32_C(0x00002304), UINT32_C(0x00007001), 
    UINT32_C(0x00004ecb), UINT32_C(0x00001fde), UINT32_C(0x00006844), UINT32_C(0x00001063), 
    UINT32_C(0x00003781), UINT32_C(0x00003968), UINT32_C(0x00000cda), UINT32_C(0x00000a40), 
    UINT32_C(0x0000614d), UINT32_C(0x00000b17), UINT32_C(0x00006ad4), UINT32_C(0x0000367e), 
    UINT32_C(0x00004c52), UINT32_C(0x00003413), UINT32_C(0x0000060a), UINT32_C(0x000025a4), 
    UINT32_C(0x000032c4), UINT32_C(0x00000249), UINT32_C(0x00003f01), UINT32_C(0x00001735), 
    UINT32_C(0x000072f2), UINT32_C(0x00004462), UINT32_C(0x00002d0f), UINT32_C(0x00007b3d), 
    UINT32_C(0x00005a83), UINT32_C(0x000077f5), UINT32_C(0x000063c0), UINT32_C(0x00003229), 
    UINT32_C(0x000036ff), UINT32_C(0x000027fb), UINT32_C(0x00002779), UINT32_C(0x00007edb), 
    UINT32_C(0x00004f92), UINT32_C(0x00000f84), UINT32_C(0x0000555b), UINT32_C(0x00005efe), 
    UINT32_C(0x00002c0d), UINT32_C(0x000054a9), UINT32_C(0x0000026a), UINT32_C(0x00003d97), 
    UINT32_C(0x00004d2e), UINT32_C(0x00006fc2), UINT32_C(0x000015ef), UINT32_C(0x000033dd), 
    UINT32_C(0x00003a21), UINT32_C(0x000012d9), UINT32_C(0x0000631b), UINT32_C(0x00004c4b), 
    UINT32_C(0x00000746), UINT32_C(0x0000255e), UINT32_C(0x000005ec), UINT32_C(0x00007bf3), 
    UINT32_C(0x00003a35), UINT32_C(0x0000281b), UINT32_C(0x00000755), UINT32_C(0x00004615), 
    UINT32_C(0x00002f00), UINT32_C(0x0000156b), UINT32_C(0x00000c99), UINT32_C(0x00003df0), 
    UINT32_C(0x000062b8), UINT32_C(0x000011a7), UINT32_C(0x000015f8), UINT32_C(0x00005ad8), 
    UINT32_C(0x00004732), UINT32_C(0x00007fe2), UINT32_C(0x0000108d), UINT32_C(0x00005289), 
    UINT32_C(0x0000040a), UINT32_C(0x00004ed6), UINT32_C(0x00003f77), UINT32_C(0x00006dbb), 
    UINT32_C(0x000048e9), UINT32_C(0x0000121d), UINT32_C(0x00004037), UINT32_C(0x00000af7), 
    UINT32_C(0x00001504), UINT32_C(0x00003ba5), UINT32_C(0x00002e59), UINT32_C(0x000043a8), 
    UINT32_C(0x000017e5), UINT32_C(0x0000095e), UINT32_C(0x00002a57), UINT32_C(0x00006775), 
    UINT32_C(0x00000f6e), UINT32_C(0x00007b35), UINT32_C(0x000047ba), UINT32_C(0x000041ce), 
    UINT32_C(0x0000471b), UINT32_C(0x00006546), UINT32_C(0x00002682), UINT32_C(0x00005dc5), 
    UINT32_C(0x00001c87), UINT32_C(0x0000724d), UINT32_C(0x00003bc8), UINT32_C(0x00003c20), 
    UINT32_C(0x00002d32), UINT32_C(0x00002a5e), UINT32_C(0x00000da2), UINT32_C(0x00002fac), 
    UINT32_C(0x00001181), UINT32_C(0x00003411), UINT32_C(0x00000001)
};
uint32_t *cur_read_len = read_length;


uint32_t read(FILE *fp)
{
    used_buffer = fread(fd, 1, (rand() % 0x8000 + 1), fp);
//         used_buffer = fread(fd, 1, *(cur_read_len++), fp);
//         calced_len += used_buffer;
//         printf("%08x bytes read this time, %08x bytes read all.\n",
//             used_buffer, calced_len);
    return used_buffer;
}


void print_arrays(const void *src, int size)
{
    const uint8_t *_src;
    int _size;
    static const char tbl[] = {
        '0', '1', '2', '3', '4', '5', '6', '7',
        '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
    };
    _src = (const uint8_t *)src;

    for (_size = 0; _size != size; ++_size) {
        cout << tbl[((_src[_size]) >> 4) & 0x0F];
        cout << tbl[((_src[_size]) >> 0) & 0x0F];
    }
}

void test_print()
{
    char buf[160];
    cout << "Testing xxx_d_print..." << endl;
    crc32_d_print(buf, &crc32d);
    cout << "CRC-32:" << endl << buf << endl;
    crc64_d_print(buf, &crc64d);
    cout << "CRC-64:" << endl << buf << endl;
    md5_d_print(buf, &md5d);
    cout << "MD-5:" << endl << buf << endl;
    sha1_d_print(buf, &sha1d);
    cout << "SHA-1:" << endl << buf << endl;
    sha224_d_print(buf, &sha224d);
    cout << "SHA-224:" << endl << buf << endl;
    sha256_d_print(buf, &sha256d);
    cout << "SHA-256:" << endl << buf << endl;
    sha384_d_print(buf, &sha384d);
    cout << "SHA-384:" << endl << buf << endl;
    sha512_d_print(buf, &sha512d);
    cout << "SHA-512:" << endl << buf << endl;
    tiger192_d_print(buf, &tiger192d);
    cout << "TIGER-192:" << endl << buf << endl;
    cout << endl;
}

void test_printw()
{
    wchar_t buf[160];
    wcout << "Testing xxx_d_printw..." << endl;
    crc32_d_printw(buf, &crc32d);
    wcout << "CRC-32:" << endl << buf << endl;
    crc64_d_printw(buf, &crc64d);
    wcout << "CRC-64:" << endl << buf << endl;
    md5_d_printw(buf, &md5d);
    wcout << "MD-5:" << endl << buf << endl;
    sha1_d_printw(buf, &sha1d);
    wcout << "SHA-1:" << endl << buf << endl;
    sha224_d_printw(buf, &sha224d);
    wcout << "SHA-224:" << endl << buf << endl;
    sha256_d_printw(buf, &sha256d);
    wcout << "SHA-256:" << endl << buf << endl;
    sha384_d_printw(buf, &sha384d);
    wcout << "SHA-384:" << endl << buf << endl;
    sha512_d_printw(buf, &sha512d);
    wcout << "SHA-512:" << endl << buf << endl;
    tiger192_d_printw(buf, &tiger192d);
    wcout << "TIGER-192:" << endl << buf << endl;
    wcout << endl;
}

void test_write()
{
    crc32_d_write(crc32, &crc32d);
    crc64_d_write(crc64, &crc64d);
    md5_d_write(md5, &md5d);
    sha1_d_write(sha1, &sha1d);
    sha224_d_write(sha224, &sha224d);
    sha256_d_write(sha256, &sha256d);
    sha384_d_write(sha384, &sha384d);
    sha512_d_write(sha512, &sha512d);
    tiger192_d_write(tiger192, &tiger192d);

    cout << "Testing xxx_d_write..." << endl;
    cout << "CRC-32:" << endl;
    print_arrays(crc32, 4);
    cout << endl;
    cout << "CRC-64:" << endl;
    print_arrays(crc64, 8);
    cout << endl;
    cout << "MD-5:" << endl;
    print_arrays(md5, 16);
    cout << endl;
    cout << "SHA-1:" << endl;
    print_arrays(sha1, 20);
    cout << endl;
    cout << "SHA-224:" << endl;
    print_arrays(sha224, 28);
    cout << endl;
    cout << "SHA-256:" << endl;
    print_arrays(sha256, 32);
    cout << endl;
    cout << "SHA-384:" << endl;
    print_arrays(sha384, 48);
    cout << endl;
    cout << "SHA-512:" << endl;
    print_arrays(sha512, 64);
    cout << endl;
    cout << "TIGER-192:" << endl;
    print_arrays(tiger192, 24);
    cout << endl;
}


//  shall be after test_writes
void test_read()
{
    char buf[160];

    crc32_d_read(&crc32d, crc32);
    crc64_d_read(&crc64d, crc64);
    md5_d_read(&md5d, md5);
    sha1_d_read(&sha1d, sha1);
    sha224_d_read(&sha224d, sha224);
    sha256_d_read(&sha256d, sha256);
    sha384_d_read(&sha384d, sha384);
    sha512_d_read(&sha512d, sha512);
    tiger192_d_read(&tiger192d, tiger192);

    cout << "Testing xxx_d_read..." << endl;
    crc32_d_print(buf, &crc32d);
    cout << "CRC-32:" << endl << buf << endl;
    crc64_d_print(buf, &crc64d);
    cout << "CRC-64:" << endl << buf << endl;
    md5_d_print(buf, &md5d);
    cout << "MD-5:" << endl << buf << endl;
    sha1_d_print(buf, &sha1d);
    cout << "SHA-1:" << endl << buf << endl;
    sha224_d_print(buf, &sha224d);
    cout << "SHA-224:" << endl << buf << endl;
    sha256_d_print(buf, &sha256d);
    cout << "SHA-256:" << endl << buf << endl;
    sha384_d_print(buf, &sha384d);
    cout << "SHA-384:" << endl << buf << endl;
    sha512_d_print(buf, &sha512d);
    cout << "SHA-512:" << endl << buf << endl;
    tiger192_d_print(buf, &tiger192d);
    cout << "TIGER-192:" << endl << buf << endl;
    cout << endl;
}




int main(int argc, char **argv)
{
    srand((unsigned)time(NULL));
    if (argc != 2) {
        printf("Wrong argument number, quiting...");
        return -1;
    }

#ifdef _MSC_VER
#pragma warning(disable : 4996)
#endif
    FILE* fp = fopen(argv[1], "rb");
#ifdef _MSC_VER
#pragma warning(default : 4996)
#endif

    if (!fp) {
        printf("Cannot open file |%s|, quiting", argv[1]);
        return -2;
    }

    crc32_c_init(&crc32c);
    crc64_c_init(&crc64c);
    md5_c_init(&md5c);
    sha1_c_init(&sha1c);
    sha224_c_init(&sha224c);
    sha256_c_init(&sha256c);
    sha384_c_init(&sha384c);
    sha512_c_init(&sha512c);
    tiger192_c_init(&tiger192c);

    while (read(fp)) {
        crc32_c_append(&crc32c, fd, used_buffer);
        crc64_c_append(&crc64c, fd, used_buffer);
        md5_c_append(&md5c, fd, used_buffer);
        sha1_c_append(&sha1c, fd, used_buffer);
        sha224_c_append(&sha224c, fd, used_buffer);
        sha256_c_append(&sha256c, fd, used_buffer);
        sha384_c_append(&sha384c, fd, used_buffer);
        sha512_c_append(&sha512c, fd, used_buffer);
        tiger192_c_append(&tiger192c, fd, used_buffer);
    }
    
//     uint8_t sample[3] = {0x61, 0x62, 0x63};
//     crc32_c_append(&crc32c, sample, 3);
//     crc64_c_append(&crc64c, sample, 3);
//     md5_c_append(&md5c, sample, 3);
//     sha1_c_append(&sha1c, sample, 3);
//     sha224_c_append(&sha224c, sample, 3);
//     sha256_c_append(&sha256c, sample, 3);
//     sha384_c_append(&sha384c, sample, 3);
//     sha512_c_append(&sha512c, sample, 3);
//     tiger192_c_append(&tiger192c, sample, 3);
    
    crc32_c_close(&crc32c);
    crc64_c_close(&crc64c);
    md5_c_close(&md5c);
    sha1_c_close(&sha1c);
    sha224_c_close(&sha224c);
    sha256_c_close(&sha256c);
    sha384_c_close(&sha384c);
    sha512_c_close(&sha512c);
    tiger192_c_close(&tiger192c);
    
    crc32_cvt(&crc32d, &crc32c);
    crc64_cvt(&crc64d, &crc64c);
    md5_cvt(&md5d, &md5c);
    sha1_cvt(&sha1d, &sha1c);
    sha224_cvt(&sha224d, &sha224c);
    sha256_cvt(&sha256d, &sha256c);
    sha384_cvt(&sha384d, &sha384c);
    sha512_cvt(&sha512d, &sha512c);
    tiger192_cvt(&tiger192d, &tiger192c);

    cout.imbue(locale(""));
    wcout.imbue(locale(""));

    test_print();
    test_printw();
    test_write();
    test_read();

    cin.get();
}